package com.yinhe.music.yhmusic.dialog;

import android.app.Activity;
import android.support.annotation.NonNull;

import com.dou361.dialogui.DialogUIUtils;
import com.dou361.dialogui.bean.BuildBean;
import com.dou361.dialogui.listener.DialogUIListener;
import com.yinhe.music.yhmusic.utils.Preferences;

/**
 * 流量保护弹窗
 */
public class NetProtectDialog {

    private NetProtectDialogListener mListener;
    private Activity mContext;
    private BuildBean builder;

    public interface NetProtectDialogListener {
        void netProtectDidConfirm();
    }

    public NetProtectDialog(@NonNull Activity context, NetProtectDialogListener listener) {
        mListener = listener;
        mContext = context;
        init();
    }

    public void show() {
        if (builder != null) {
            builder.show();
        }
    }

    public void init() {
        DialogUIListener listener = new DialogUIListener() {
            @Override
            public void onPositive() {
                Preferences.setIsProtect(false);
                mListener.netProtectDidConfirm();
            }

            @Override
            public void onNegative() {

            }
        };

        builder = DialogUIUtils.showAlert(mContext, "是否继续下载？",
                "已启用流量保护，2G/3G/4G下载会产生较多流量", null,
                null, "关闭流量保护", "取消", false,
                false, false, listener);
    }
}
